// pages/ck_qs/ck_qs.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
 
  zhidao:function(e){
    var that = this;
    that.setData({
      yc_s:"display:none"
    })
  },
  zhidao1:function(e){
    var that = this;
    that.setData({
      yc_s:"display:none"
    })
  },
  yulan:function(e){
    var yl_id = e.currentTarget.dataset.id; 
    wx.navigateTo({
      url: '../xq_wendang/xq_wendang?yl_id='+yl_id,
    })
  },
  gr_xx:function(e){
    var gr_id = e.currentTarget.dataset.id; 
    wx.navigateTo({
      url: '../moban_doc/moban_doc?gr_id='+gr_id,
    })
  },
  sh_xq1:function(e){
     var that = this;
     var ys_id = e.currentTarget.dataset.id; 
     wx.request({
      url: app.globalData.url_l + 'api/order/muban_shengeng',
      method: 'post',
      data:{
          id:ys_id
      },
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if(res.data.code==1){
          wx.showToast({
            title: '验收成功！',
            icon: 'success',
            duration: 2000,
            success:function(){
              setTimeout(function () {
                //要延时执行的代码
                wx.request({
                  url: app.globalData.url_l + 'api/order/muban_shenxiang',
                  method: 'post',
                  data:{
                      id:app.globalData.sh_id1
                  },
                  method: 'post',
                  header: {
                    'content-type': 'application/x-www-form-urlencoded'
                  },
                  success: function (res) {
                    console.log(11111111)
                    console.log(res)
                    that.setData({
                      mb_xq:res.data.data
                    })
                   
                  },
                })
              }, 2000) //延迟时间
            }
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
       
      },
    })
  },
  sh_xq2:function(e){
    var url = e.currentTarget.dataset.url;
    //下载文件，生成临时地址
    wx.downloadFile({
      url: url, 
      success(res) {
        // console.log(res)
        //保存到本地
        wx.saveFile({
          tempFilePath: res.tempFilePath,
          success: function (res) {
            const savedFilePath = res.savedFilePath;
            // 打开文件
            wx.openDocument({
              filePath: savedFilePath,
              success: function (res) {
                console.log(res)
                console.log('打开文档成功')
              },
            });
          },
          fail: function (err) {
            console.log('保存失败：', err)
          }
        });
      }
    })
  },
  sh_xq3:function(e){
    var that = this;
    console.log(1)
    that.setData({
      yc_s:"display:block"
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      var sh_id = options.sh_id;
      app.globalData.sh_id1 = sh_id
      wx.request({
        url: app.globalData.url_l + 'api/order/muban_shenxiang',
        method: 'post',
        data:{
            id:app.globalData.sh_id1
        },
        method: 'post',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(11111111)
          console.log(res)
          that.setData({
            mb_xq:res.data.data
          })
         
        },
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})